package com.daxue.common.http.core;

import com.daxue.common.http.utils.RateLimiterConfig;

/**
 * @author daxue0929
 * @date 2022/4/7
 */

public interface RateLimiterBuilder {

    String BASE_LIMITER_PATH = "ratelimiter";

    RateLimiter build(String name, RateLimiterConfig config);

    default TokenBucket toBucket(RateLimiterConfig config) {
        return TokenBucket.newInstance()
            .setMaxPermits(config.getMaxPermits())
            .setIntervalMillis(config.getIntervalMillis())
            .setGrantFactor(config.getGrantFactor());
    }

}
